home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 1
/
CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso
/
Aminet
/
comm
/
mail
/
AirMail.lha
/
AirMail
/
AM_EditorScript.lha
/
editor.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1995-06-07
|
7KB
|
291 lines
/* editor.rexx ... script for AirMail to do external editor */
/* cleanly... */
/* By Rick Taylor (charlet@hubcap.clemson.edu) */
/* Last update 6-7-95 */
/* See documentation for more details - although this */
/* script _does_ contain many comments ... :) */
/* ... minor fixes to handle the latest Airmail beta */
/* ... attachments should now work */
/* ... now checks for "SENT" mail - duh */
/* ... Make blank localfiule while editing */
/* Built from modhdr (on Aminet) on June 1, 1995 */
/* Environment variables: */
/* AIREDITOR = pathname of your editor */
/* AIRPAGER = pathname of your pager */
/* Initialize */
call addlib("rexxreqtools.library",0,-30,0)
options results
lf = '0a'x
cr = '0d'x
colon='3a'x
semicol='3b'x
qmark='22'x
fonttag=""
aflags=""
address command
/* Intercept the filename */
localfile = ARG(1)
/* Get file comment */
localfilec = readcomment(localfile)
/* Create filenames ... */
tmpstem = ".atmp"
cmdstem = ".acmd"
hdrstem = ".ahdr"
suffstem = "T:"
tmpfile = "T:0.atmp"
cmdfile = "T:0.acmd"
hdrfile = "T:0.ahdr"
flcounter = 0
do while (exists(tmpfile)|exists(cmdfile)|exists(hdrfile)) = 1
flcounter = flcounter + 1
tmpfile = suffstem||strip(flcounter)||tmpstem
cmdfile = suffstem||strip(flcounter)||cmdstem
hdrfile = suffstem||strip(flcounter)||hdrstem
end
'echo >'tmpfile
'echo >'cmdfile
'echo >'hdrfile
/* Signature file? Sheesh ... */
checkforsig=upper(right(localfile,12))
if checkforsig="SIGNATURE.AM" then do
if ~exists(localfile) then do
'echo >'localfile
end
call open .dae,cmdfile,write
call writeln .dae,envar('AIREDITOR') localfile
call close .dae
'execute 'cmdfile
dummy = cleanup('OK')
exit
end
/* Open file */
dummy = open(mf,localfile,read)
/* Read headers */
mailtype = readln(mf)
mto = readln(mf)
replyto = readln(mf)
date = readln(mf)
subject = readln(mf)
mcc = readln(mf)
mbcc = readln(mf)
blankline = readln(mf)
if mcc = "" then mcc = "<None>"
/* Create file with just the message */
call open tf,tmpfile,write
do until eof(mf)=1
call writeln tf, readln(mf)
end
call close mf
call close tf
/* Here's where we part ways if it's not a file we need to edit.... */
if index(localfilec,"OLD") > 0 then mailtype="QUEUED MAIL"
if index(localfilec,"SENT") > 0 then mailtype="SENT MAIL"
if mailtype ~= "AIRMAIL" then do
call open .dae,cmdfile,write
call writeln .dae,envar('AIRPAGER') localfile
call close .dae
'execute 'cmdfile
dummy = cleanup('OK')
exit
end
/* Get rid of the localfile ... we'll assemble it later */
'echo >'localfile
/* Let's ask the user about the headers ... */
whoto = mto
msub = subject
if strip(mto)="" then do
whoto = getval(mto," Who to mail this to? (user@host) ")
end
if (strip(subject)="")|(subject="ENTER SUBJECT HERE") then do
msub = getval(subject," Enter a subject for this mail: ")
end
/* Edit the temporary (headerless horseman) file */
call open .dae,cmdfile,write
call writeln .dae,envar('AIREDITOR') tmpfile
call close .dae
'execute 'cmdfile
/* Change header options */
hdflag = -1
do until hdflag = 0
hdmsg = "To : "||whoto||lf||"Subject: "||msub||lf||"Attacht: "mcc||lf||"Date : "||date
hdbuttons = "_To|_Subject|_Attachments|A_bort Mail|_Queue Mail!"
hdflag = rtezrequest(hdmsg,hdbuttons,"Select an option...","")
select
when hdflag = 1 then do
mto = whoto
mtxt = " Who to mail this to? (user@host) "
whoto = getval(mto,mtxt)
end
when hdflag = 2 then do
subject = msub
msub = getval(subject," Enter a subject for this mail: ")
end
when hdflag = 3 then do
mtxt = "What file to attach to this mail?"
defpath="RAM:"
mcc = getfname(mtxt,defpath)
if mcc = "<None>" then mcc = "ENTER ATTACHMENT HERE"
end
when hdflag = 4 then do
dummy = cleanup('ABORT')
exit
end
otherwise
end
end
/* Now that we've edited this file we should put together a message with */
/* headers */
call open hdr,hdrfile,write
/* Write headers */
/* Note: "mbcc" is really the X-Mailer header for purposes of */
/* Airmail. Also, "mcc" is really the attachment */
/* header ... */
call writeln hdr,mailtype
call writeln hdr,whoto
call writeln hdr,replyto
call writeln hdr,date
call writeln hdr,msub
call writeln hdr,mcc
call writeln hdr,mbcc
call writeln hdr,""
call close hdr
/* Recreate localfile */
'join 'hdrfile' 'tmpfile' AS 'localfile
/* Write the file comment */
call writecomment localfile,'QUEUED OLD'
/* Return control to the caller ... */
dummy = cleanup('OK')
exit
/* Cleanup function ... */
cleanup:
arg cleanuptype
if cleanuptype="ABORT" then do
'delete 'localfile' QUIET'
end
'delete 'tmpfile' QUIET'
'delete 'cmdfile' QUIET'
'delete 'hdrfile' QUIET'
return cleanuptype
/* Useful subprograms follow ... */
getval: procedure
parse arg defsub,msg
mailsub = rtgetstring(defsub,msg,"ModHdr/AM by Rick Taylor","Ok","")
if mailsub = "" then mailsub = defsub
if mailsub = "" then mailsub = "<None>"
return mailsub
diagnostic: procedure
parse arg showit
msg = "Value = "||showit
cf=rtezrequest(msg,"OK","Diagnostic","")
return cf
envar: procedure
arg evname
epath = "ENV:"||evname
evalue = ""
if exists(epath) then do
call open .envar,epath,read
evalue = readln(.envar)
call close .envar
end
return evalue
getfname: procedure
parse arg msg,defdir
filename=""
fonttag = ""
parse arg dummy
filename = rtfilerequest(defdir, , msg , , fonttag "rtfi_buffer = true")
return filename
readcomment: procedure
arg flname
flcomment = ""
address command
if exists('ENV:DRMCOMMENT') then do
'delete ENV:DRMCOMMENT QUIET'
end
if exists(flname) then do
'list 'flname' LFORMAT=%C >ENV:DRMCOMMENT'
flcomment = envar('DRMCOMMENT')
end
return flcomment
writecomment: procedure
parse arg flname,flcomment
qmark='22'x
qcomment=qmark||flcomment||qmark
if exists(flname) then do
'filenote 'flname qcomment
end
return flcomment